package GUINotYetImplemented;

import java.awt.EventQueue;
import ControlLayer.CtrPerson;
import ModelLayer.*;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.TitledBorder;
import javax.swing.JComboBox;

public class OpretKunde {

	private JFrame frame;
	private JTextField navnText;
	private JTextField addressText;
	private JTextField cityText;
	private JTextField zipCodeText;
	private JTextField emailText;
	private JTextField cvrNoText;
	private JTextField accountNoText;
	private JTextField phoneNoText;
	private JTextField idCustomerText;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					OpretKunde window = new OpretKunde();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public OpretKunde() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	
	
	
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 835, 705);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		
		addressText = new JTextField();
		addressText.setColumns(10);
		addressText.setBounds(98, 73, 246, 20);
		frame.getContentPane().add(addressText);
		
		cityText = new JTextField();
		cityText.setColumns(10);
		cityText.setBounds(98, 104, 246, 20);
		frame.getContentPane().add(cityText);
		
		zipCodeText = new JTextField();
		zipCodeText.setColumns(10);
		zipCodeText.setBounds(98, 135, 91, 20);
		frame.getContentPane().add(zipCodeText);
		
		emailText = new JTextField();
		emailText.setColumns(10);
		emailText.setBounds(523, 42, 154, 20);
		frame.getContentPane().add(emailText);
		
		cvrNoText = new JTextField();
		cvrNoText.setColumns(10);
		cvrNoText.setBounds(523, 104, 154, 20);
		frame.getContentPane().add(cvrNoText);
		
		accountNoText = new JTextField();
		accountNoText.setColumns(10);
		accountNoText.setBounds(523, 135, 154, 20);
		frame.getContentPane().add(accountNoText);
		
		phoneNoText = new JTextField();
		phoneNoText.setColumns(10);
		phoneNoText.setBounds(523, 73, 154, 20);
		frame.getContentPane().add(phoneNoText);
		
		JLabel lblNavn = new JLabel("Navn");
		lblNavn.setBounds(35, 40, 32, 14);
		frame.getContentPane().add(lblNavn);
		
		JLabel lblAdresse = new JLabel("Adresse");
		lblAdresse.setBounds(21, 76, 46, 14);
		frame.getContentPane().add(lblAdresse);
		
		JLabel lblBy = new JLabel("By");
		lblBy.setBounds(46, 107, 21, 14);
		frame.getContentPane().add(lblBy);
		
		JLabel lblBy_1 = new JLabel("Post Nummer");
		lblBy_1.setBounds(46, 138, 70, 14);
		frame.getContentPane().add(lblBy_1);
		
		JLabel lblEmail = new JLabel("Email");
		lblEmail.setBounds(470, 43, 46, 14);
		frame.getContentPane().add(lblEmail);
		
		JLabel lblCvrNummer = new JLabel("Cvr nummer");
		lblCvrNummer.setBounds(458, 107, 58, 14);
		frame.getContentPane().add(lblCvrNummer);
		
		JLabel lblKontoNummer = new JLabel("Konto nummer");
		lblKontoNummer.setBounds(441, 138, 70, 14);
		frame.getContentPane().add(lblKontoNummer);
		
		JLabel lblId = new JLabel("Telefon nummer");
		lblId.setBounds(441, 79, 82, 14);
		frame.getContentPane().add(lblId);
		
		JButton btnSgEfterKunde = new JButton("S\u00F8g efter kunde");
		btnSgEfterKunde.addActionListener(new ActionListener() {
			
//			S�gefunktion til at finde Customer
			public void actionPerformed(java.awt.event.ActionEvent evt) 
			{
				CtrPerson ctrPer = new CtrPerson();
				Customer cus = new Customer();
				String idCustomer = idCustomerText.getText();
				
				if(idCustomer.length() == 0)
				{
					
				}	
				else
				{
					try {
						cus = ctrPer.findCus(idCustomer);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					navnText.setText(cus.getName());
					addressText.setText(cus.getAddress());
					cityText.setText(cus.getCity());
					zipCodeText.setText(cus.getZipCode());
					emailText.setText(cus.getEmail());
					cvrNoText.setText(cus.getCvrNo());
					accountNoText.setText(cus.getAccountNo());
					phoneNoText.setText(cus.getPhoneNo());
				}
			}
		});
		btnSgEfterKunde.setBounds(708, 70, 109, 23);
		frame.getContentPane().add(btnSgEfterKunde);
		
		idCustomerText = new JTextField();
		idCustomerText.setBounds(255, 135, 89, 20);
		frame.getContentPane().add(idCustomerText);
		idCustomerText.setColumns(10);
		
		JLabel lblKundeId = new JLabel("Kunde ID");
		lblKundeId.setBounds(199, 135, 46, 14);
		frame.getContentPane().add(lblKundeId);
		
		JButton btnOpretKunde = new JButton("Opret kunde");
		btnOpretKunde.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnOpretKunde.setBounds(708, 36, 109, 23);
		frame.getContentPane().add(btnOpretKunde);
		
		JButton btnOpdaterKunde = new JButton("Opdater kunde");
		btnOpdaterKunde.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnOpdaterKunde.setBounds(708, 104, 109, 23);
		frame.getContentPane().add(btnOpdaterKunde);
		
		JButton btnSletKunde = new JButton("Slet kunde");
		btnSletKunde.setBounds(708, 140, 109, 23);
		frame.getContentPane().add(btnSletKunde);
		
		navnText = new JTextField();
		navnText.setBounds(98, 37, 246, 20);
		frame.getContentPane().add(navnText);
		navnText.setColumns(10);
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "Tilbud", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.setBounds(21, 191, 784, 456);
		frame.getContentPane().add(panel);
		panel.setLayout(null);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setBounds(34, 31, 115, 22);
		panel.add(comboBox);
		
		JComboBox comboBox_1 = new JComboBox();
		comboBox_1.setVisible(false);
		comboBox_1.setBounds(204, 31, 128, 22);
		panel.add(comboBox_1);
	}
	
	private void findCus(java.awt.event.ActionEvent evt)
	{
		CtrPerson ctrPer = new CtrPerson();
		Customer ctrCus = new Customer();
		String idCustomer = idCustomerText.getText();
		
		if(idCustomer.length() == 0)
		{
			
		}	
		else
		{
			try {
				ctrCus = ctrPer.findCus(idCustomer);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			navnText.setText(ctrCus.getName());
		}
	}
}
